import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);

var state = {
	game:[]
}
// 持久化：从本地取出数据
if(localStorage.getItem("data")) {
	var data = JSON.parse(localStorage.getItem("data"));
	state = data;
}

function saveTolocal(state) {
	// 持久化：保存数据
	localStorage.setItem("data", JSON.stringify(state));
}
const mutations = {
	addGame: function(state,game){
		state.game.push(game);
		saveTolocal(state);
	}
}

const actions = {
	addGameA : function({commit},game){
		commit("addGame",game);
	}
}

export default new Vuex.Store({
	state,
	mutations,
	actions
})
